home *** CD-ROM | disk | FTP | other *** search
- Subject: Re: FW_CArcShape::HitTest does not seem to work
- Sent: 7/15/96 3:53 PM
- Received: 7/15/96 4:31 PM
- From: Henri Lamiraux, lamiraux@apple.com
- Reply-To: ODF Interest, ODF-Interest@CILabs.ORG
- To: OpenDoc Development Framework Discussion List, ODF-Interest@CILabs.
-
- >I have a little pie chart part that I am doing some hit testing on. I
- >want to
- >pass in a point to each section of the pie for hit testing to determine
- >which section the point is in. However, no matter where the point is in
- >the pie, the first section always returns a hit. I looked at the code and
- >the problem seems to be in the CalcAngle function. I'm no mathemetician,
- >but it seems to me that a function that always returns zero can't be doing
- >what it's supposed to! :-)
- >
- >What's the deal?
- >Walter
-
- This is the fix for FW_CArcShape::CalcAngle that will be in ODF Release 2:
-
- //-------------------------------------------------------------------------
- ---------------
- // FW_CArcShape::CalcAngle
- //-------------------------------------------------------------------------
- ---------------
-
- short FW_CArcShape::CalcAngle(const FW_CPoint& test) const
- {
- FW_Double width = FW_FixedToDouble(fRect.right - fRect.left);
- FW_Double height = FW_FixedToDouble(fRect.bottom - fRect.top);
-
- FW_CPoint testPoint(FW_Half(test.x + test.x - fRect.right - fRect.left),
- FW_Half(test.y + test.y - fRect.bottom - fRect.top));
-
- if (testPoint.y == FW_kFixed0 || height == 0)
- return testPoint.x < FW_kFixed0 ? 270 : 90;
-
- if (testPoint.x == FW_kFixed0 || width == 0)
- return testPoint.y < FW_kFixed0 ? 180 : 0;
-
- FW_Double arc = atan((FW_FixedToDouble(testPoint.y) * height) /
- (FW_FixedToDouble(testPoint.x) * width));
-
- arc = ((180.0 * arc) / 3.1415926536) + .5;
- short shortArc = (short)arc + 90;
- if (testPoint.x < FW_kFixed0)
- shortArc += 180;
-
- return shortArc;
- }
-
-
- ........................................................................
- Henri Lamiraux lamiraux@apple.com
- Apple Computer, Inc. OpenDoc(tm) Development Framework
- ........................................................................
-
-
-